package com.ss.android.wenda.b;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.frameworks.baselib.network.http.util.HttpQueryHelper;
import com.ss.android.action.b.FeedViewHolder;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.app.a.ArticleConstants;
import com.ss.android.article.base.feature.app.schema.AdsAppActivity;
import com.ss.android.article.base.feature.feed.FeedCellStyleConfig;
import com.ss.android.article.base.feature.feed.k;
import com.ss.android.article.base.feature.feed.FeedOnMovedToScrapHeapListener;
import com.ss.android.article.base.feature.model.CellRef;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.NightModeAsyncImageView;
import com.ss.android.article.common.entity.wenda.WendaEntity.Answer;
import com.ss.android.article.common.entity.wenda.WendaEntity.Question;
import com.ss.android.article.common.entity.wenda.WendaEntity.WendaExtra;
import com.ss.android.article.common.entity.wenda.WendaEntity.WendaImage;
import com.ss.android.image.AsyncImageView;
import com.ss.android.image.Image;
import com.ss.android.j.ClickableBackgroundCompat;

import java.util.concurrent.atomic.AtomicBoolean;

public final class a extends FeedViewHolder implements k, FeedOnMovedToScrapHeapListener {
    public final class a$a implements View.OnClickListener {
        String a;
        private Context b;

        public a$a(Context arg1, String arg2) {

            this.b = arg1;
            this.a = arg2;
        }

        public final void onClick(View arg4) {
            if(!TextUtils.isEmpty(this.a)) {
                AdsAppActivity.openUrl(this.b, this.a, null);
            }
        }
    }

    public View A;
    public View B;
    public boolean C;
    private a$a D;
    private CellRef E;
    private AppData F;
    private Context G;
    private boolean H;
    private boolean I;
    private AtomicBoolean J;
    private int K;
    private int L;
    public View o;
    public TextView p;
    public TextView q;
    public AsyncImageView r;
    public AsyncImageView s;
    public AsyncImageView t;
    public TextView u;
    public TextView v;
    public TextView w;
    public View x;
    public View y;
    public View z;

    public a(Context arg2, AtomicBoolean arg3, int arg4, int arg5) {

        this.C = false;
        this.H = false;
        this.G = arg2;
        this.J = arg3;
        this.F = AppData.getInstance();
        this.K = arg4;
        this.L = arg5;
    }

    private static void a(ImageView arg1) {
        if(arg1 != null) {
            android.support.design.a.removeImageInfoTag(arg1);
            arg1.setImageDrawable(null);
        }
    }

    private static void a(ImageView arg1, Image arg2) {
        android.support.design.a.setListImageHolder(arg1);
        if(arg2 == null) {
            arg1.setTag(null);
        }
        else if(arg1 != null) {
            arg1.setEnabled(true);
            arg1.setTag(com.ss.android.article.browser.R.id.image_info, arg2);
        }
    }

    private static void a(AsyncImageView arg4) {
        Object v0;
        int v3 = R.id.image_info;
        Object v1 = null;
        if(arg4 == null || ((ImageView)arg4).getVisibility() != View.VISIBLE) {
            v0 = v1;
        }
        else {
            v0 = ((ImageView)arg4).getTag(v3);
            if(v0 != null && ((v0 instanceof Image))) {
            }else {
                v0 = v1;
            }
        }

        if(v0 != null) {
            arg4.setImage(((Image)v0));
            arg4.setTag(v3, v1);
        }
    }

    public final void a(CellRef arg12, int arg13, int arg14) {
        int v6 = R.color.ssxinzi3;
        int v10 = 3;
        int v3 = 8;
        if(arg12 != null) {
            if(this.I) {
                Logger.throwException("status dirty ! This should not occur !");
                this.onMovedToScrapHeap();
            }

            this.I = true;
            this.E = arg12;
            int v0 = (arg12.l) || arg13 == arg14 - 1 ? 1 : 0;
            View v4 = this.y;
            v0 = v0 != 0 ? v3 : 0;
            UIUtils.setVisibility(v4, v0);
            if(this.C != AppData.isNightMode()) {
                this.C = AppData.isNightMode();
                ClickableBackgroundCompat.setClickableBackground(this.o, this.C);
                this.x.setBackgroundColor(ContextCompat.getColor(this.G, R.color.ssxinmian3));
                this.y.setBackgroundColor(ContextCompat.getColor(this.G, R.color.ssxinmian3));
                this.p.setTextColor(ContextCompat.getColor(this.G, R.color.item_text));
                this.q.setTextColor(ContextCompat.getColor(this.G, R.color.update_comment_more_text_selector));
                this.u.setTextColor(ContextCompat.getColor(this.G, v6));
                this.v.setTextColor(ContextCompat.getColor(this.G, v6));
                this.w.setTextColor(ContextCompat.getColor(this.G, v6));
                this.A.setBackgroundColor(ContextCompat.getColor(this.G, R.color.divider));
                this.B.setBackgroundColor(ContextCompat.getColor(this.G, R.color.divider));
                if((this.r instanceof NightModeAsyncImageView)) {
                    ((NightModeAsyncImageView)this.r).adaptNightMode(this.C);
                }

                if((this.s instanceof NightModeAsyncImageView)) {
                    ((NightModeAsyncImageView) this.s).adaptNightMode(this.C);
                }

                if(!(this.t instanceof NightModeAsyncImageView)) {
                }else {
                    ((NightModeAsyncImageView)this.t).adaptNightMode(this.C);
                }
            }

            this.C = AppData.isNightMode();
            if(this.E == null) {
                return;
            }

            if(this.E.wendaEntity == null) {
                return;
            }

            if(this.E == null) {
                return;
            }

            Question v4_1 = this.E.wendaEntity.question;
            if(v4_1 != null) {
                this.p.setText(v4_1.title);
                this.q.setText(this.G.getString(com.ss.android.article.browser.R.string.wd_answer_count, new Object[]{Integer.valueOf(v4_1.nice_ans_count + v4_1.normal_ans_count)}));
            }

            Answer v0_1 = this.E.wendaEntity.answer;
            WendaExtra v5 = this.E.wendaEntity.extra;
            if(v0_1 == null || v5 == null || !v5.show_answer) {
                UIUtils.setVisibility(this.z, v3);
            }
            else {
                this.u.setText(v0_1.abstra);
                this.v.setText(v0_1.uname);
                this.w.setText(this.G.getString(com.ss.android.article.browser.R.string.wd_digg_count, new Object[]{Integer.valueOf(v0_1.digg_count)}));
                UIUtils.setVisibility(this.z, 0);
            }

            if(this.F != null) {
                v0 = this.F.mFontSizePref;
                if(v0 < 0 || v0 > v10) {
                    v0 = 0;
                }

                FeedCellStyleConfig.setTextSize(this.p, ArticleConstants.G[v0]);
                if(UIUtils.isVisible(this.q)) {
                    this.q.setTextSize(((float) ArticleConstants.M[v0]));
                }

                if(!UIUtils.isVisible(this.z)) {
                }else {
                    if (UIUtils.isVisible(this.u)) {
                        this.u.setTextSize(((float) ArticleConstants.M[v0]));
                    }

                    if (UIUtils.isVisible(this.v)) {
                        this.v.setTextSize(((float) ArticleConstants.M[v0]));
                    }

                    if (!UIUtils.isVisible(this.w)) {
                    } else {
                        this.w.setTextSize(((float) ArticleConstants.M[v0]));
                    }
                }
            }
            if(v5 != null && v5.wenda_image != null) {
                boolean v6_1 = this.J.get();
                WendaImage v7 = v5.wenda_image;
                if(v7.large_image_list == null || (v7.large_image_list.isEmpty())) {
                    UIUtils.setVisibility(this.t, v3);
                    if(v7.small_image_list != null && !v7.small_image_list.isEmpty()) {
                        UIUtils.setVisibility(this.r, 0);
                        UIUtils.setVisibility(this.s, v3);
                        a.a(this.r, (Image) v7.small_image_list.get(0));
                    }else {
                        UIUtils.setVisibility(this.r, v3);
                        if (v7.medium_image_list != null && !v7.medium_image_list.isEmpty()) {
                            UIUtils.setVisibility(this.s, 0);
                            ViewGroup.LayoutParams v0_2 = this.s.getLayoutParams();
                            if (this.K <= 0 || this.L <= 0 || (android.support.design.a.o(this.G))) {
                                v0_2.width = com.ss.android.article.base.feature.app.a.b.f;
                                v0_2.height = com.ss.android.article.base.feature.app.a.b.g;
                            } else {
                                v0_2.width = this.K;
                                v0_2.height = this.L;
                            }

                            this.s.setLayoutParams(v0_2);
                            a.a(this.s, (Image) v7.medium_image_list.get(0));
                        } else {
                            UIUtils.setVisibility(this.s, v3);
                        }
                    }
                } else {
                    UIUtils.setVisibility(this.t, 0);
                    UIUtils.setVisibility(this.s, v3);
                    a.a(this.t, (Image) v7.large_image_list.get(0));
                    if(v7.small_image_list != null && !v7.small_image_list.isEmpty()) {
                        UIUtils.setVisibility(this.r, 0);
                        a.a(this.r, (Image) v7.small_image_list.get(0));
                    }else {
                        UIUtils.setVisibility(this.r, v3);
                    }
                }

                if(!v6_1) {
                    this.loadImage();
                    this.H = false;
                }else {
                    this.H = true;
                }
            }

            if(UIUtils.isVisible(this.s)) {
                UIUtils.setMaxLines(this.p, v10);
            }
            else {
                UIUtils.setMaxLines(this.p, 2);
            }

            if(v5 != null) {
                if(v5.show_answer) {
                    if(UIUtils.isVisible(this.r)) {
                        UIUtils.setMaxLines(this.u, v10);
                    }
                    else {
                        UIUtils.setMaxLines(this.u, 2);
                    }
                }

                String v0_3 = v5.schema;
                if(TextUtils.isEmpty(((CharSequence)v0_3))) {
                    HttpQueryHelper v0_4 = new HttpQueryHelper("sslocal://wenda_list");
                    v0_4.put("qid", v4_1.qid);
                    v0_3 = v0_4.getEncodeQuery();
                }

                if(this.D == null) {
                    this.D = new a$a(this.G, v0_3);
                }else {
                    this.D.a = v0_3;
                }
            }

            this.o.setOnClickListener(this.D);
        }
    }

    public final boolean d() {
        return this.H;
    }

    public final void e() {
        this.H = false;
    }

    public final void loadImage() {
        a.a(this.r);
        a.a(this.s);
        a.a(this.t);
    }

    public final void onMovedToScrapHeap() {
        this.I = false;
        this.H = false;
        if(this.o != null) {
            this.o.setOnClickListener(null);
        }

        a.a(this.r);
        a.a(this.s);
        a.a(this.t);
    }
}

